﻿using MediatR;
using System.Security.Claims;
using T.Contract.API.Application.Command.ContractCommand;
using T.Contract.Domain.T.Contract.Model;
using T.Contract.Repository.Interface;

namespace T.Contract.API.Application.CommandHandlers.ContractHandler
{
    public class ContratDeleteCommandHandler : IRequestHandler<ContratDeleteCommand, int>
    {


        protected readonly IContractRepository contractRepository;

        public ContratDeleteCommandHandler(IContractRepository contractRepository)
        {
            this.contractRepository = contractRepository;
        }

        public async Task<int> Handle(ContratDeleteCommand request, CancellationToken cancellationToken)
        {
            var id=request.ContractId;
            foreach (var item in id)
            {
                var res =  await contractRepository.GetModelAsync(item);
                res.IsDeleted = true;
                res.DeletedBy = request.DeletedBy;
                res.DeletedDate = request.DeletedDate;
               await contractRepository.UpdateAsync(res);
            }
            return 1;
        }
    }
}
